@pod-os/elements 0.31.1-rc.4c5bdf8.0 → 0.31.1-rc.85d0b38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16877,9 +16877,13 @@ var ExtensionManager = class {
16877
16877
  if (!addNodeView) {
16878
16878
  return [];
16879
16879
  }
16880
+ const nodeViewResult = addNodeView();
16881
+ if (!nodeViewResult) {
16882
+ return [];
16883
+ }
16880
16884
  const nodeview = (node, view, getPos, decorations, innerDecorations) => {
16881
16885
  const HTMLAttributes = getRenderedAttributes(node, extensionAttributes);
16882
- return addNodeView()({
16886
+ return nodeViewResult({
16883
16887
  // pass-through
16884
16888
  node,
16885
16889
  view,
@@ -17619,6 +17623,7 @@ var Editor = class extends EventEmitter {
17619
17623
  constructor(options = {}) {
17620
17624
  super();
17621
17625
  this.css = null;
17626
+ this.className = "tiptap";
17622
17627
  this.editorView = null;
17623
17628
  this.isFocused = false;
17624
17629
  /**
@@ -17731,7 +17736,7 @@ var Editor = class extends EventEmitter {
17731
17736
  }
17732
17737
  this.editorView = null;
17733
17738
  this.isInitialized = false;
17734
- if (this.css) {
17739
+ if (this.css && !document.querySelectorAll(`.${this.className}`).length) {
17735
17740
  try {
17736
17741
  if (typeof this.css.remove === "function") {
17737
17742
  this.css.remove();
@@ -18011,7 +18016,7 @@ var Editor = class extends EventEmitter {
18011
18016
  * Prepend class name to element.
18012
18017
  */
18013
18018
  prependClass() {
18014
- this.view.dom.className = `tiptap ${this.view.dom.className}`;
18019
+ this.view.dom.className = `${this.className} ${this.view.dom.className}`;
18015
18020
  }
18016
18021
  captureTransaction(fn) {
18017
18022
  this.isCapturingTransaction = true;
@@ -18285,6 +18290,537 @@ function wrappingInputRule(config) {
18285
18290
  undoable: config.undoable
18286
18291
  });
18287
18292
  }
18293
+
18294
+ // src/lib/ResizableNodeView.ts
18295
+ var isTouchEvent = (e) => {
18296
+ return "touches" in e;
18297
+ };
18298
+ var ResizableNodeView = class {
18299
+ /**
18300
+ * Creates a new ResizableNodeView instance.
18301
+ *
18302
+ * The constructor sets up the resize handles, applies initial sizing from
18303
+ * node attributes, and configures all resize behavior options.
18304
+ *
18305
+ * @param options - Configuration options for the resizable node view
18306
+ */
18307
+ constructor(options) {
18308
+ /** Active resize handle directions */
18309
+ this.directions = ["bottom-left", "bottom-right", "top-left", "top-right"];
18310
+ /** Minimum allowed dimensions */
18311
+ this.minSize = {
18312
+ height: 8,
18313
+ width: 8
18314
+ };
18315
+ /** Whether to always preserve aspect ratio */
18316
+ this.preserveAspectRatio = false;
18317
+ /** CSS class names for elements */
18318
+ this.classNames = {
18319
+ container: "",
18320
+ wrapper: "",
18321
+ handle: "",
18322
+ resizing: ""
18323
+ };
18324
+ /** Initial width of the element (for aspect ratio calculation) */
18325
+ this.initialWidth = 0;
18326
+ /** Initial height of the element (for aspect ratio calculation) */
18327
+ this.initialHeight = 0;
18328
+ /** Calculated aspect ratio (width / height) */
18329
+ this.aspectRatio = 1;
18330
+ /** Whether a resize operation is currently active */
18331
+ this.isResizing = false;
18332
+ /** The handle currently being dragged */
18333
+ this.activeHandle = null;
18334
+ /** Starting mouse X position when resize began */
18335
+ this.startX = 0;
18336
+ /** Starting mouse Y position when resize began */
18337
+ this.startY = 0;
18338
+ /** Element width when resize began */
18339
+ this.startWidth = 0;
18340
+ /** Element height when resize began */
18341
+ this.startHeight = 0;
18342
+ /** Whether Shift key is currently pressed (for temporary aspect ratio lock) */
18343
+ this.isShiftKeyPressed = false;
18344
+ /**
18345
+ * Handles mouse movement during an active resize.
18346
+ *
18347
+ * Calculates the delta from the starting position, computes new dimensions
18348
+ * based on the active handle direction, applies constraints and aspect ratio,
18349
+ * then updates the element's style and calls the onResize callback.
18350
+ *
18351
+ * @param event - The mouse move event
18352
+ */
18353
+ this.handleMouseMove = (event) => {
18354
+ if (!this.isResizing || !this.activeHandle) {
18355
+ return;
18356
+ }
18357
+ const deltaX = event.clientX - this.startX;
18358
+ const deltaY = event.clientY - this.startY;
18359
+ this.handleResize(deltaX, deltaY);
18360
+ };
18361
+ this.handleTouchMove = (event) => {
18362
+ if (!this.isResizing || !this.activeHandle) {
18363
+ return;
18364
+ }
18365
+ const touch = event.touches[0];
18366
+ if (!touch) {
18367
+ return;
18368
+ }
18369
+ const deltaX = touch.clientX - this.startX;
18370
+ const deltaY = touch.clientY - this.startY;
18371
+ this.handleResize(deltaX, deltaY);
18372
+ };
18373
+ /**
18374
+ * Completes the resize operation when the mouse button is released.
18375
+ *
18376
+ * Captures final dimensions, calls the onCommit callback to persist changes,
18377
+ * removes the resizing state and class, and cleans up document-level listeners.
18378
+ */
18379
+ this.handleMouseUp = () => {
18380
+ if (!this.isResizing) {
18381
+ return;
18382
+ }
18383
+ const finalWidth = this.element.offsetWidth;
18384
+ const finalHeight = this.element.offsetHeight;
18385
+ this.onCommit(finalWidth, finalHeight);
18386
+ this.isResizing = false;
18387
+ this.activeHandle = null;
18388
+ this.container.dataset.resizeState = "false";
18389
+ if (this.classNames.resizing) {
18390
+ this.container.classList.remove(this.classNames.resizing);
18391
+ }
18392
+ document.removeEventListener("mousemove", this.handleMouseMove);
18393
+ document.removeEventListener("mouseup", this.handleMouseUp);
18394
+ document.removeEventListener("keydown", this.handleKeyDown);
18395
+ document.removeEventListener("keyup", this.handleKeyUp);
18396
+ };
18397
+ /**
18398
+ * Tracks Shift key state to enable temporary aspect ratio locking.
18399
+ *
18400
+ * When Shift is pressed during resize, aspect ratio is preserved even if
18401
+ * preserveAspectRatio is false.
18402
+ *
18403
+ * @param event - The keyboard event
18404
+ */
18405
+ this.handleKeyDown = (event) => {
18406
+ if (event.key === "Shift") {
18407
+ this.isShiftKeyPressed = true;
18408
+ }
18409
+ };
18410
+ /**
18411
+ * Tracks Shift key release to disable temporary aspect ratio locking.
18412
+ *
18413
+ * @param event - The keyboard event
18414
+ */
18415
+ this.handleKeyUp = (event) => {
18416
+ if (event.key === "Shift") {
18417
+ this.isShiftKeyPressed = false;
18418
+ }
18419
+ };
18420
+ var _a, _b, _c, _d, _e;
18421
+ this.node = options.node;
18422
+ this.element = options.element;
18423
+ this.contentElement = options.contentElement;
18424
+ this.getPos = options.getPos;
18425
+ this.onResize = options.onResize;
18426
+ this.onCommit = options.onCommit;
18427
+ this.onUpdate = options.onUpdate;
18428
+ if ((_a = options.options) == null ? void 0 : _a.min) {
18429
+ this.minSize = {
18430
+ ...this.minSize,
18431
+ ...options.options.min
18432
+ };
18433
+ }
18434
+ if ((_b = options.options) == null ? void 0 : _b.max) {
18435
+ this.maxSize = options.options.max;
18436
+ }
18437
+ if ((_c = options == null ? void 0 : options.options) == null ? void 0 : _c.directions) {
18438
+ this.directions = options.options.directions;
18439
+ }
18440
+ if ((_d = options.options) == null ? void 0 : _d.preserveAspectRatio) {
18441
+ this.preserveAspectRatio = options.options.preserveAspectRatio;
18442
+ }
18443
+ if ((_e = options.options) == null ? void 0 : _e.className) {
18444
+ this.classNames = {
18445
+ container: options.options.className.container || "",
18446
+ wrapper: options.options.className.wrapper || "",
18447
+ handle: options.options.className.handle || "",
18448
+ resizing: options.options.className.resizing || ""
18449
+ };
18450
+ }
18451
+ this.wrapper = this.createWrapper();
18452
+ this.container = this.createContainer();
18453
+ this.applyInitialSize();
18454
+ this.attachHandles();
18455
+ }
18456
+ /**
18457
+ * Returns the top-level DOM node that should be placed in the editor.
18458
+ *
18459
+ * This is required by the ProseMirror NodeView interface. The container
18460
+ * includes the wrapper, handles, and the actual content element.
18461
+ *
18462
+ * @returns The container element to be inserted into the editor
18463
+ */
18464
+ get dom() {
18465
+ return this.container;
18466
+ }
18467
+ get contentDOM() {
18468
+ return this.contentElement;
18469
+ }
18470
+ /**
18471
+ * Called when the node's content or attributes change.
18472
+ *
18473
+ * Updates the internal node reference. If a custom `onUpdate` callback
18474
+ * was provided, it will be called to handle additional update logic.
18475
+ *
18476
+ * @param node - The new/updated node
18477
+ * @param decorations - Node decorations
18478
+ * @param innerDecorations - Inner decorations
18479
+ * @returns `false` if the node type has changed (requires full rebuild), otherwise the result of `onUpdate` or `true`
18480
+ */
18481
+ update(node, decorations, innerDecorations) {
18482
+ if (node.type !== this.node.type) {
18483
+ return false;
18484
+ }
18485
+ this.node = node;
18486
+ if (this.onUpdate) {
18487
+ return this.onUpdate(node, decorations, innerDecorations);
18488
+ }
18489
+ return true;
18490
+ }
18491
+ /**
18492
+ * Cleanup method called when the node view is being removed.
18493
+ *
18494
+ * Removes all event listeners to prevent memory leaks. This is required
18495
+ * by the ProseMirror NodeView interface. If a resize is active when
18496
+ * destroy is called, it will be properly cancelled.
18497
+ */
18498
+ destroy() {
18499
+ if (this.isResizing) {
18500
+ this.container.dataset.resizeState = "false";
18501
+ if (this.classNames.resizing) {
18502
+ this.container.classList.remove(this.classNames.resizing);
18503
+ }
18504
+ document.removeEventListener("mousemove", this.handleMouseMove);
18505
+ document.removeEventListener("mouseup", this.handleMouseUp);
18506
+ document.removeEventListener("keydown", this.handleKeyDown);
18507
+ document.removeEventListener("keyup", this.handleKeyUp);
18508
+ this.isResizing = false;
18509
+ this.activeHandle = null;
18510
+ }
18511
+ this.container.remove();
18512
+ }
18513
+ /**
18514
+ * Creates the outer container element.
18515
+ *
18516
+ * The container is the top-level element returned by the NodeView and
18517
+ * wraps the entire resizable node. It's set up with flexbox to handle
18518
+ * alignment and includes data attributes for styling and identification.
18519
+ *
18520
+ * @returns The container element
18521
+ */
18522
+ createContainer() {
18523
+ const element = document.createElement("div");
18524
+ element.dataset.resizeContainer = "";
18525
+ element.dataset.node = this.node.type.name;
18526
+ element.style.display = "flex";
18527
+ element.style.justifyContent = "flex-start";
18528
+ element.style.alignItems = "flex-start";
18529
+ if (this.classNames.container) {
18530
+ element.className = this.classNames.container;
18531
+ }
18532
+ element.appendChild(this.wrapper);
18533
+ return element;
18534
+ }
18535
+ /**
18536
+ * Creates the wrapper element that contains the content and handles.
18537
+ *
18538
+ * The wrapper uses relative positioning so that resize handles can be
18539
+ * positioned absolutely within it. This is the direct parent of the
18540
+ * content element being made resizable.
18541
+ *
18542
+ * @returns The wrapper element
18543
+ */
18544
+ createWrapper() {
18545
+ const element = document.createElement("div");
18546
+ element.style.position = "relative";
18547
+ element.style.display = "block";
18548
+ element.dataset.resizeWrapper = "";
18549
+ if (this.classNames.wrapper) {
18550
+ element.className = this.classNames.wrapper;
18551
+ }
18552
+ element.appendChild(this.element);
18553
+ return element;
18554
+ }
18555
+ /**
18556
+ * Creates a resize handle element for a specific direction.
18557
+ *
18558
+ * Each handle is absolutely positioned and includes a data attribute
18559
+ * identifying its direction for styling purposes.
18560
+ *
18561
+ * @param direction - The resize direction for this handle
18562
+ * @returns The handle element
18563
+ */
18564
+ createHandle(direction) {
18565
+ const handle = document.createElement("div");
18566
+ handle.dataset.resizeHandle = direction;
18567
+ handle.style.position = "absolute";
18568
+ if (this.classNames.handle) {
18569
+ handle.className = this.classNames.handle;
18570
+ }
18571
+ return handle;
18572
+ }
18573
+ /**
18574
+ * Positions a handle element according to its direction.
18575
+ *
18576
+ * Corner handles (e.g., 'top-left') are positioned at the intersection
18577
+ * of two edges. Edge handles (e.g., 'top') span the full width or height.
18578
+ *
18579
+ * @param handle - The handle element to position
18580
+ * @param direction - The direction determining the position
18581
+ */
18582
+ positionHandle(handle, direction) {
18583
+ const isTop = direction.includes("top");
18584
+ const isBottom = direction.includes("bottom");
18585
+ const isLeft = direction.includes("left");
18586
+ const isRight = direction.includes("right");
18587
+ if (isTop) {
18588
+ handle.style.top = "0";
18589
+ }
18590
+ if (isBottom) {
18591
+ handle.style.bottom = "0";
18592
+ }
18593
+ if (isLeft) {
18594
+ handle.style.left = "0";
18595
+ }
18596
+ if (isRight) {
18597
+ handle.style.right = "0";
18598
+ }
18599
+ if (direction === "top" || direction === "bottom") {
18600
+ handle.style.left = "0";
18601
+ handle.style.right = "0";
18602
+ }
18603
+ if (direction === "left" || direction === "right") {
18604
+ handle.style.top = "0";
18605
+ handle.style.bottom = "0";
18606
+ }
18607
+ }
18608
+ /**
18609
+ * Creates and attaches all resize handles to the wrapper.
18610
+ *
18611
+ * Iterates through the configured directions, creates a handle for each,
18612
+ * positions it, attaches the mousedown listener, and appends it to the DOM.
18613
+ */
18614
+ attachHandles() {
18615
+ this.directions.forEach((direction) => {
18616
+ const handle = this.createHandle(direction);
18617
+ this.positionHandle(handle, direction);
18618
+ handle.addEventListener("mousedown", (event) => this.handleResizeStart(event, direction));
18619
+ handle.addEventListener("touchstart", (event) => this.handleResizeStart(event, direction));
18620
+ this.wrapper.appendChild(handle);
18621
+ });
18622
+ }
18623
+ /**
18624
+ * Applies initial sizing from node attributes to the element.
18625
+ *
18626
+ * If width/height attributes exist on the node, they're applied to the element.
18627
+ * Otherwise, the element's natural/current dimensions are measured. The aspect
18628
+ * ratio is calculated for later use in aspect-ratio-preserving resizes.
18629
+ */
18630
+ applyInitialSize() {
18631
+ const width = this.node.attrs.width;
18632
+ const height = this.node.attrs.height;
18633
+ if (width) {
18634
+ this.element.style.width = `${width}px`;
18635
+ this.initialWidth = width;
18636
+ } else {
18637
+ this.initialWidth = this.element.offsetWidth;
18638
+ }
18639
+ if (height) {
18640
+ this.element.style.height = `${height}px`;
18641
+ this.initialHeight = height;
18642
+ } else {
18643
+ this.initialHeight = this.element.offsetHeight;
18644
+ }
18645
+ if (this.initialWidth > 0 && this.initialHeight > 0) {
18646
+ this.aspectRatio = this.initialWidth / this.initialHeight;
18647
+ }
18648
+ }
18649
+ /**
18650
+ * Initiates a resize operation when a handle is clicked.
18651
+ *
18652
+ * Captures the starting mouse position and element dimensions, sets up
18653
+ * the resize state, adds the resizing class and state attribute, and
18654
+ * attaches document-level listeners for mouse movement and keyboard input.
18655
+ *
18656
+ * @param event - The mouse down event
18657
+ * @param direction - The direction of the handle being dragged
18658
+ */
18659
+ handleResizeStart(event, direction) {
18660
+ event.preventDefault();
18661
+ event.stopPropagation();
18662
+ this.isResizing = true;
18663
+ this.activeHandle = direction;
18664
+ if (isTouchEvent(event)) {
18665
+ this.startX = event.touches[0].clientX;
18666
+ this.startY = event.touches[0].clientY;
18667
+ } else {
18668
+ this.startX = event.clientX;
18669
+ this.startY = event.clientY;
18670
+ }
18671
+ this.startWidth = this.element.offsetWidth;
18672
+ this.startHeight = this.element.offsetHeight;
18673
+ if (this.startWidth > 0 && this.startHeight > 0) {
18674
+ this.aspectRatio = this.startWidth / this.startHeight;
18675
+ }
18676
+ this.getPos();
18677
+ this.container.dataset.resizeState = "true";
18678
+ if (this.classNames.resizing) {
18679
+ this.container.classList.add(this.classNames.resizing);
18680
+ }
18681
+ document.addEventListener("mousemove", this.handleMouseMove);
18682
+ document.addEventListener("touchmove", this.handleTouchMove);
18683
+ document.addEventListener("mouseup", this.handleMouseUp);
18684
+ document.addEventListener("keydown", this.handleKeyDown);
18685
+ document.addEventListener("keyup", this.handleKeyUp);
18686
+ }
18687
+ handleResize(deltaX, deltaY) {
18688
+ if (!this.activeHandle) {
18689
+ return;
18690
+ }
18691
+ const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed;
18692
+ const { width, height } = this.calculateNewDimensions(this.activeHandle, deltaX, deltaY);
18693
+ const constrained = this.applyConstraints(width, height, shouldPreserveAspectRatio);
18694
+ this.element.style.width = `${constrained.width}px`;
18695
+ this.element.style.height = `${constrained.height}px`;
18696
+ if (this.onResize) {
18697
+ this.onResize(constrained.width, constrained.height);
18698
+ }
18699
+ }
18700
+ /**
18701
+ * Calculates new dimensions based on mouse delta and resize direction.
18702
+ *
18703
+ * Takes the starting dimensions and applies the mouse movement delta
18704
+ * according to the handle direction. For corner handles, both dimensions
18705
+ * are affected. For edge handles, only one dimension changes. If aspect
18706
+ * ratio should be preserved, delegates to applyAspectRatio.
18707
+ *
18708
+ * @param direction - The active resize handle direction
18709
+ * @param deltaX - Horizontal mouse movement since resize start
18710
+ * @param deltaY - Vertical mouse movement since resize start
18711
+ * @returns The calculated width and height
18712
+ */
18713
+ calculateNewDimensions(direction, deltaX, deltaY) {
18714
+ let newWidth = this.startWidth;
18715
+ let newHeight = this.startHeight;
18716
+ const isRight = direction.includes("right");
18717
+ const isLeft = direction.includes("left");
18718
+ const isBottom = direction.includes("bottom");
18719
+ const isTop = direction.includes("top");
18720
+ if (isRight) {
18721
+ newWidth = this.startWidth + deltaX;
18722
+ } else if (isLeft) {
18723
+ newWidth = this.startWidth - deltaX;
18724
+ }
18725
+ if (isBottom) {
18726
+ newHeight = this.startHeight + deltaY;
18727
+ } else if (isTop) {
18728
+ newHeight = this.startHeight - deltaY;
18729
+ }
18730
+ if (direction === "right" || direction === "left") {
18731
+ newWidth = this.startWidth + (isRight ? deltaX : -deltaX);
18732
+ }
18733
+ if (direction === "top" || direction === "bottom") {
18734
+ newHeight = this.startHeight + (isBottom ? deltaY : -deltaY);
18735
+ }
18736
+ const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed;
18737
+ if (shouldPreserveAspectRatio) {
18738
+ return this.applyAspectRatio(newWidth, newHeight, direction);
18739
+ }
18740
+ return { width: newWidth, height: newHeight };
18741
+ }
18742
+ /**
18743
+ * Applies min/max constraints to dimensions.
18744
+ *
18745
+ * When aspect ratio is NOT preserved, constraints are applied independently
18746
+ * to width and height. When aspect ratio IS preserved, constraints are
18747
+ * applied while maintaining the aspect ratio—if one dimension hits a limit,
18748
+ * the other is recalculated proportionally.
18749
+ *
18750
+ * This ensures that aspect ratio is never broken when constrained.
18751
+ *
18752
+ * @param width - The unconstrained width
18753
+ * @param height - The unconstrained height
18754
+ * @param preserveAspectRatio - Whether to maintain aspect ratio while constraining
18755
+ * @returns The constrained dimensions
18756
+ */
18757
+ applyConstraints(width, height, preserveAspectRatio) {
18758
+ var _a, _b, _c, _d;
18759
+ if (!preserveAspectRatio) {
18760
+ let constrainedWidth2 = Math.max(this.minSize.width, width);
18761
+ let constrainedHeight2 = Math.max(this.minSize.height, height);
18762
+ if ((_a = this.maxSize) == null ? void 0 : _a.width) {
18763
+ constrainedWidth2 = Math.min(this.maxSize.width, constrainedWidth2);
18764
+ }
18765
+ if ((_b = this.maxSize) == null ? void 0 : _b.height) {
18766
+ constrainedHeight2 = Math.min(this.maxSize.height, constrainedHeight2);
18767
+ }
18768
+ return { width: constrainedWidth2, height: constrainedHeight2 };
18769
+ }
18770
+ let constrainedWidth = width;
18771
+ let constrainedHeight = height;
18772
+ if (constrainedWidth < this.minSize.width) {
18773
+ constrainedWidth = this.minSize.width;
18774
+ constrainedHeight = constrainedWidth / this.aspectRatio;
18775
+ }
18776
+ if (constrainedHeight < this.minSize.height) {
18777
+ constrainedHeight = this.minSize.height;
18778
+ constrainedWidth = constrainedHeight * this.aspectRatio;
18779
+ }
18780
+ if (((_c = this.maxSize) == null ? void 0 : _c.width) && constrainedWidth > this.maxSize.width) {
18781
+ constrainedWidth = this.maxSize.width;
18782
+ constrainedHeight = constrainedWidth / this.aspectRatio;
18783
+ }
18784
+ if (((_d = this.maxSize) == null ? void 0 : _d.height) && constrainedHeight > this.maxSize.height) {
18785
+ constrainedHeight = this.maxSize.height;
18786
+ constrainedWidth = constrainedHeight * this.aspectRatio;
18787
+ }
18788
+ return { width: constrainedWidth, height: constrainedHeight };
18789
+ }
18790
+ /**
18791
+ * Adjusts dimensions to maintain the original aspect ratio.
18792
+ *
18793
+ * For horizontal handles (left/right), uses width as the primary dimension
18794
+ * and calculates height from it. For vertical handles (top/bottom), uses
18795
+ * height as primary and calculates width. For corner handles, uses width
18796
+ * as the primary dimension.
18797
+ *
18798
+ * @param width - The new width
18799
+ * @param height - The new height
18800
+ * @param direction - The active resize direction
18801
+ * @returns Dimensions adjusted to preserve aspect ratio
18802
+ */
18803
+ applyAspectRatio(width, height, direction) {
18804
+ const isHorizontal = direction === "left" || direction === "right";
18805
+ const isVertical = direction === "top" || direction === "bottom";
18806
+ if (isHorizontal) {
18807
+ return {
18808
+ width,
18809
+ height: width / this.aspectRatio
18810
+ };
18811
+ }
18812
+ if (isVertical) {
18813
+ return {
18814
+ width: height * this.aspectRatio,
18815
+ height
18816
+ };
18817
+ }
18818
+ return {
18819
+ width,
18820
+ height: width / this.aspectRatio
18821
+ };
18822
+ }
18823
+ };
18288
18824
  function canInsertNode(state, nodeType) {
18289
18825
  const { selection } = state;
18290
18826
  const { $from } = selection;
@@ -20260,6 +20796,7 @@ var Document = Node3.create({
20260
20796
  // src/hard-break.ts
20261
20797
  var HardBreak = Node3.create({
20262
20798
  name: "hardBreak",
20799
+ markdownTokenName: "br",
20263
20800
  addOptions() {
20264
20801
  return {
20265
20802
  keepMarks: true,
@@ -20281,6 +20818,11 @@ var HardBreak = Node3.create({
20281
20818
  },
20282
20819
  renderMarkdown: (_node, h) => h.indent(`
20283
20820
  `),
20821
+ parseMarkdown: () => {
20822
+ return {
20823
+ type: "hardBreak"
20824
+ };
20825
+ },
20284
20826
  addCommands() {
20285
20827
  return {
20286
20828
  setHardBreak: () => ({ commands, chain, state, editor }) => {
@@ -25344,7 +25886,8 @@ var Image = Node3.create({
25344
25886
  return {
25345
25887
  inline: false,
25346
25888
  allowBase64: false,
25347
- HTMLAttributes: {}
25889
+ HTMLAttributes: {},
25890
+ resize: false
25348
25891
  };
25349
25892
  },
25350
25893
  inline() {
@@ -25397,6 +25940,69 @@ var Image = Node3.create({
25397
25940
  const title = (_f = (_e = node.attrs) == null ? void 0 : _e.title) != null ? _f : "";
25398
25941
  return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
25399
25942
  },
25943
+ addNodeView() {
25944
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined" || !this.editor.isEditable) {
25945
+ return null;
25946
+ }
25947
+ const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
25948
+ return ({ node, getPos, HTMLAttributes }) => {
25949
+ const el = document.createElement("img");
25950
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
25951
+ if (value != null) {
25952
+ switch (key) {
25953
+ case "width":
25954
+ case "height":
25955
+ break;
25956
+ default:
25957
+ el.setAttribute(key, value);
25958
+ break;
25959
+ }
25960
+ }
25961
+ });
25962
+ el.src = HTMLAttributes.src;
25963
+ const nodeView = new ResizableNodeView({
25964
+ element: el,
25965
+ node,
25966
+ getPos,
25967
+ onResize: (width, height) => {
25968
+ el.style.width = `${width}px`;
25969
+ el.style.height = `${height}px`;
25970
+ },
25971
+ onCommit: (width, height) => {
25972
+ const pos = getPos();
25973
+ if (pos === void 0) {
25974
+ return;
25975
+ }
25976
+ this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
25977
+ width,
25978
+ height
25979
+ }).run();
25980
+ },
25981
+ onUpdate: (updatedNode, _decorations, _innerDecorations) => {
25982
+ if (updatedNode.type !== node.type) {
25983
+ return false;
25984
+ }
25985
+ return true;
25986
+ },
25987
+ options: {
25988
+ directions,
25989
+ min: {
25990
+ width: minWidth,
25991
+ height: minHeight
25992
+ },
25993
+ preserveAspectRatio: alwaysPreserveAspectRatio === true
25994
+ }
25995
+ });
25996
+ const dom = nodeView.dom;
25997
+ dom.style.visibility = "hidden";
25998
+ dom.style.pointerEvents = "none";
25999
+ el.onload = () => {
26000
+ dom.style.visibility = "";
26001
+ dom.style.pointerEvents = "";
26002
+ };
26003
+ return nodeView;
26004
+ };
26005
+ },
25400
26006
  addCommands() {
25401
26007
  return {
25402
26008
  setImage: (options) => ({ commands }) => {